package com.yzg.controller;

import com.yzg.pojo.FlashPromotion;
import com.yzg.service.FlashPromotionService;
import com.yzg.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import java.util.Map;

/**
 * @author 杨鹏
 * @Date 项目创建日期为 2021/1/14
 * @copyright 项目版权归作者所有
 */
@Api(tags = "FlashPromotionController", description = "秒杀活动列表")
@RestController
@RequestMapping("/flashPromotion")
public class FlashPromotionController {

    @Autowired
    private FlashPromotionService flashPromotionService;

    /**
     * 秒杀活动列表实现
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "秒杀活动列表")
    public R list(Integer pageNum, Integer pageSize, String keyword){
        Map<String,Object> map= flashPromotionService.list(pageNum,pageSize,keyword);
        return R.ok().data(map);
    }


    /**
     * 上线/下线(秒杀活动)
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    @ApiOperation(value = "'秒杀活动(启用状态：0->不启用；1->启用)'")
    public R updateStatus(@PathVariable Long id,Integer status){
        int row = flashPromotionService.updateStatus(id, status);
        if (row>0){
            return R.ok();
        }else {
            return R.error();
        }
    }


    /**
     * 秒杀活动添加
     * @param flashPromotion
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "秒杀活动添加")
    public R savaCreate(FlashPromotion flashPromotion){
       int row= flashPromotionService.savaCreate(flashPromotion);
        if (row>0){
            return R.ok();
        }else {
            return R.error();
        }
    }

    /**
     * 编辑秒杀列表活动
     * @param flashPromotion
     * @return
     */
    @ApiOperation(value = "编辑秒杀列表活动")
    @PostMapping("/update/{id}")
    public R updateActive(FlashPromotion flashPromotion){
        int row=flashPromotionService.updateActive(flashPromotion);
        if (row>0){
            return R.ok();
        }else {
            return R.error();
        }
    }

}
